﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microhard.Permission.Interfaces;
using Micrhard.FMCG.Server.DataAccess;
using Micrhard.FMCG.Server.Models;

namespace Micrhard.FMCG.Server.Impl
{
    public class ViewPrdDisplayDPValidator : ICustomeDataPermissionValidator
    {
        public bool HasPermission(List<Guid> identity)
        {
            bool result = false;
            MicrhardFMCGServerEntities db = new MicrhardFMCGServerEntities();
            var image = db.ProductDisplayImages.SingleOrDefault(p => identity.Contains(p.ImageID));
            var emp = db.Employees.SingleOrDefault(e => e.UserName == this.scope.CurrentUserName);
            if (emp.Range == (int)Range.Monitor || emp.Range == (int)Range.Saler)
            {
                var cnt = emp.ManagementScopes.Count(m => m.SubKA.CustomerCode == image.SubKACode);
                result = cnt > 0 ? true : false;
            }
            else if (emp.Range == (int)Range.Manager)
            {
                result = true;
            }
            return result;
        }

        public Microhard.Core.DBUtility.ScopeResult scope
        {
            set;
            get;
        }
    }
}
